<template>
  <view>
    <van-popup v-model="showCompo" closeable round position="bottom" :style="{ height: '50%' }"
               @click-close-icon="toClose" @click-overlay="toClose">
      <view style="padding-top: 80rpx;">
        <van-cell is-link title="开始时间" :value="startDate" @click="showStart = true" />
        <van-calendar v-model="showStart" :show-confirm="false" @confirm="startConfirm" />
        <van-cell is-link title="结束时间" :value="endDate" @click="showEnd = true" />
        <van-calendar v-model="showEnd" :show-confirm="false" @confirm="endConfirm" />
      </view>
      <view style="padding-top: 100rpx;">
        <van-row type="flex" justify="space-around">
          <van-col span="10">
            <van-button type="info" round plain hairline block @click="toClose">取消</van-button>
          </van-col>
          <van-col span="10">
            <van-button type="info" round block @click="toSave">确定</van-button>
          </van-col>
        </van-row>
      </view>
    </van-popup>
  </view>
</template>
<script>
export default {
  props: {
    showLimit: {
      type: Boolean,
      default: false
    },
    detailObj: {
      type: Object,
      default: {}
    },
  },

  watch: {
    showLimit(val) {
      this.showCompo = val;
    },
    detailObj: {
      handler(nval, oval) {
        console.log(nval)
        if(this.util.isNotEmpty(nval)){
          this.startDate = nval.startTime;
          this.endDate = nval.endlineTime;
          this.proInstId = nval.proInstId;
        }
      },
      deep: true,
      immediate: true
    },
  },

  data() {
    return {
      showCompo: false,
      proInstId: '',
      startDate: '',
      endDate: '',
      showStart: false,
      showEnd: false,
    }
  },

  methods: {
    toClose() {
      this.$emit('closeLimit', this.showCompo)
    },

    toSave() {
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/doc/sw/updatebjsx`),
        method: 'post',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'proInstId': this.proInstId,
          'startTime': this.startDate,
          'endlineTime': this.endDate
        })
      }).then(({data}) => {
        if(data.code==200){
          this.$toast('修改成功')
          this.$emit('closeLimit', this.showCompo)
          this.$emit('refreshBtnGroup', true);
        }

      })
    },

    formatDate(date) {
      let month = `${date.getMonth() + 1 >= 10 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1)}`;
      let day = `${date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()}`;
      return `${date.getFullYear()}-${month}-${day}`;
    },

    startConfirm(date) {
      this.showStart = false;
      this.startDate = this.formatDate(date);
    },

    endConfirm(date) {
      this.showEnd = false;
      this.endDate = this.formatDate(date);
    },
  }
}
</script>
<style lang="less">

</style>
